<?php
/**
 * Helper callback function for ArrayWalker::trim()
 *
 * trim an item
 *
 * @param mixed $item Array item to trim
 */
function phpinchains_ArrayWalker_trim_hlp (&$item) {
    $item = trim($item);
}

/**
 * Helper callback function for ArrayWalker::split()
 * 
 * Split an item
 *
 * @param mixed $item Array item to split
 */
function phpinchains_ArrayWalker_split_hlp (&$item, $key, $options) {
    $item = split($options[0], $item);
    if ($options[1])
        $item = ArrayWalker::trim($item);
}

/**
 * Class with static utility functions used to manipulate array elements
 *
 */
class ArrayWalker {
    
    /**
     * Walks an array and trims every element
     *
     * @param array $array Array with elements to trim
     */
    static function trim ($array) {
        $success = array_walk($array, "phpinchains_ArrayWalker_trim_hlp");
        if ($success) {
            return $array;
        } else {
            return array();
        }

    }

    /**
     * Walks an array and splits every element with separator
     *
     * @param array  $array     Array with elements to trim
     * @param string $separator String to separate elements
     * @param bool   $trim      Shall the split elements be trimmed?
	 */
    static function split ($array, $separator, $trim = true) {
        $success = array_walk($array, "phpinchains_ArrayWalker_split_hlp", array($separator, $trim));
        if ($success) {
            return $array;
        } else {
            return array();
        }

    }

}
?>